package com.wc.acwing.二分.管道;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/15 8:28
 * @description 管道
 * https://www.acwing.com/problem/content/5410/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m;
    static int maxN = (int) 1e5 + 7;
    static ArrayList<Pair> segs;
    static int[] ls = new int[maxN];
    static int[] ts = new int[maxN];

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            ls[i] = sc.nextInt();
            ts[i] = sc.nextInt();
        }
        out.println(bs());
        out.flush();
    }

    static long bs() {
        long l = 0;
        long r = (int) 2e9;
        while (l < r) {
            long mid = l + r >> 1;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return r;
    }

    static boolean check(long mid) {
        segs = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if (mid >= ts[i]) {
                long t = mid - ts[i];
                int st = (int) Math.max(1, ls[i] - t);
                int ed = (int) Math.min(m, (long) ls[i] + t);
                segs.add(new Pair(st, ed));
            }
        }
        segs.sort(Pair::compareTo);
        int st = -1;
        int ed = -1;
        for (Pair seg : segs) {
            if (ed + 1 < seg.x) {
                st = seg.x;
                ed = seg.y;
            } else {
                ed = Math.max(ed, seg.y);
            }
        }
        return st == 1 && ed == m;
    }

    static class Pair implements Comparable<Pair> {
        int x, y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}